package edu.unika.aifb.graphindex.searcher.keyword.evaluation;

import java.util.HashMap;

import edu.unika.aifb.graphindex.model.IEntity;
import edu.unika.aifb.graphindex.query.QNode;

public class CombineScore {
	
	public static double combineEntityScore(HashMap<QNode, IEntity> nodeToEntity){
		double combineScore = 0;
		double nodesWithZeroScore = 0;
		for(QNode node : nodeToEntity.keySet()){
			IEntity entity = nodeToEntity.get(node);
			if(entity != null){
				if(entity.getScore() == 0)
					nodesWithZeroScore++;
				combineScore += entity.getScore();
			}
			else{
				double nodeScore = 0;
				if(node.isKeywordNode())
					nodeScore = node.getTopEntity().getScore();
				else
					nodeScore = 0;
				
				if(nodeScore == 0)
					nodesWithZeroScore++;
				combineScore += nodeScore;
			}
		}
		combineScore = combineScore / (nodeToEntity.keySet().size() - nodesWithZeroScore);
		return combineScore;
	}

}
